package com.c.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.c.entity.Address;
import com.c.entity.Permission;
import com.c.entity.Role;
import com.c.entity.User;
import com.c.mapper.AddressMapper;
import com.c.mapper.PermissionMapper;
import com.c.mapper.RoleMapper;
import com.c.mapper.UserMapper;
import com.c.service.AddressService;
import com.c.service.UserService;
import com.c.utils.MessageConstant;
import com.c.utils.PageResult;
import com.c.utils.QueryPageBean;
import com.c.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * @author wangxiangli
 * @create 2022-12-25-12:30
 */
@Service
@Transactional
public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> implements AddressService {

    /**
     * 地址分页查询
     *
     * @param queryPageBean
     * @return
     */
    @Override
    public PageResult pageQuery(QueryPageBean queryPageBean) {
        IPage<Address> pageAddress=new Page<>(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        QueryWrapper<Address> wrapper=new QueryWrapper();
        String queryString = queryPageBean.getQueryString();
        //判断条件值是否为空，如果不为空拼接条件
        if (queryPageBean.getQueryString() != null && queryPageBean.getQueryString().length() > 0) {
            queryString = queryPageBean.getQueryString().trim();// 去除查询条件首尾空格
            wrapper.like("companyAddress",queryString);
        }
        IPage page1 = baseMapper.selectPage(pageAddress, wrapper);
        return new PageResult(page1.getTotal(),page1.getRecords());
    }
}
